package com.studentManagement.daoImpl;

import com.studentManagement.dao.ScheduleDao;
import com.studentManagement.po.Schedule;
import com.studentManagement.utils.JdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by Administrator on 2017/5/17 0017.
 */
public class ScheduleDaoImpl implements ScheduleDao {
    private Connection conn = JdbcUtil.getConnection();
    private ResultSet resultSet = null;
    private PreparedStatement preparedStatement = null;
    @Override
    public Schedule queryAllSchedule(String schedule_class_id, String schedule_year,String schedule_term) {
        Schedule schedule=new Schedule();
        String sql="SELECT * FROM schedule WHERE schedule_class_id=? AND schedule_year=? AND schedule_term=?";
        try {
            preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1,schedule_class_id);
            preparedStatement.setString(2,schedule_year);
            preparedStatement.setString(3,schedule_term);
            resultSet= preparedStatement.executeQuery();
            while (resultSet.next()){
                schedule.setSchedule_id(resultSet.getString(1));
                schedule.setSchedule_class_id(resultSet.getString(2));
                schedule.setSchedule_year(resultSet.getString(3));
                schedule.setSchedule_term(resultSet.getString(4));
                schedule.setSchedule_Monday_first(resultSet.getString(5));
                schedule.setSchedule_Monday_second(resultSet.getString(6));
                schedule.setSchedule_Monday_third(resultSet.getString(7));
                schedule.setSchedule_Monday_fourth(resultSet.getString(8));
                schedule.setSchedule_Monday_fifth(resultSet.getString(9));
                schedule.setSchedule_Tuesday_first(resultSet.getString(10));
                schedule.setSchedule_Tuesday_second(resultSet.getString(11));
                schedule.setSchedule_Tuesday_third(resultSet.getString(12));
                schedule.setSchedule_Tuesday_fourth(resultSet.getString(13));
                schedule.setSchedule_Tuesday_fifth(resultSet.getString(14));
                schedule.setSchedule_Wednesday_first(resultSet.getString(15));
                schedule.setSchedule_Wednesday_second(resultSet.getString(16));
                schedule.setSchedule_Wednesday_third(resultSet.getString(17));
                schedule.setSchedule_Wednesday_fourth(resultSet.getString(18));
                schedule.setSchedule_Wednesday_fifth(resultSet.getString(19));
                schedule.setSchedule_Thursday_first(resultSet.getString(20));
                schedule.setSchedule_Thursday_second(resultSet.getString(21));
                schedule.setSchedule_Thursday_third(resultSet.getString(22));
                schedule.setSchedule_Thursday_fourth(resultSet.getString(23));
                schedule.setSchedule_Thursday_fifth(resultSet.getString(24));
                schedule.setSchedule_Friday_first(resultSet.getString(25));
                schedule.setSchedule_Friday_second(resultSet.getString(26));
                schedule.setSchedule_Friday_third(resultSet.getString(27));
                schedule.setSchedule_Friday_fourth(resultSet.getString(28));
                schedule.setSchedule_Friday_fifth(resultSet.getString(29));
                schedule.setSchedule_Saturday_first(resultSet.getString(30));
                schedule.setSchedule_Saturday_second(resultSet.getString(31));
                schedule.setSchedule_Saturday_third(resultSet.getString(32));
                schedule.setSchedule_Saturday_fourth(resultSet.getString(33));
                schedule.setSchedule_Saturday_fifth(resultSet.getString(34));
                schedule.setSchedule_Sunday_first(resultSet.getString(35));
                schedule.setSchedule_Sunday_second(resultSet.getString(36));
                schedule.setSchedule_Sunday_third(resultSet.getString(37));
                schedule.setSchedule_Sunday_fourth(resultSet.getString(38));
                schedule.setSchedule_Sunday_fifth(resultSet.getString(39));
                schedule.setSchedule_note(resultSet.getString(40));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JdbcUtil.closeStatementAndResultSet(resultSet,preparedStatement);
            JdbcUtil.closeConnection(conn);
        }

        return schedule;
    }
}
